var mouse = {
    down : false,
    target : false,

    addStart : function(canvas) {
        canvas.bind("mousedown touchstart", function(event) {
            mouse.down = event;
            mouse.target = $(event.target);
            mouse.target.left = mouse.target.position().left;
            mouse.target.top = mouse.target.position().top;
            $("body").disableSelection();
        });
    },

    addMove : function(body) {
        body.bind("mousemove touchmove", function (event) {
            if (!mouse.target || !mouse.down) {
                return;
            }
            event.preventDefault();
            var touch = event.type === "touchmove";
            var ecx = touch ? event.originalEvent.pageX : event.clientX;
            var ecy = touch ? event.originalEvent.pageY : event.clientY;
            var mdx = touch ? mouse.down.originalEvent.pageX : mouse.down.clientX;
            var mdy = touch ? mouse.down.originalEvent.pageY : mouse.down.clientY;
            var left = mouse.target.left + (ecx - mdx);
            var top = mouse.target.top + (ecy - mdy);
            if (40 < left) {
                mouse.target.css({ left:Math.min(720, left) });
            } else if (left < 720) {
                mouse.target.css({ left:Math.max(40, left) });
            }
            if (40 < top) {
                mouse.target.css({ top:Math.min(320, top) });
            } else if (top < 320) {
                mouse.target.css({ top:Math.max(40, top) });
            }
        });
    }
};